package cn.mdmm.service.impl.pageContent;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.mdmm.entity.pageContent.PageContentInfoModel;
import cn.mdmm.entity.type.TypeInfoModel;
import cn.mdmm.mapper.pageContent.PageContentInfoMapper;
import cn.mdmm.service.pageContent.PageContentInfoService;
import cn.mdmm.service.type.TypeInfoService;
import cn.modoumama.page.GridDataModel;
import cn.modoumama.page.Page;
import cn.modoumama.service.base.impl.BaseServiceImpl;


/**
* 类名称：PageContentInfo对象定义<br>
* 类描述：页面语言分类信息表业务实现类<br>
* 类生产方式：工具自动生成代码<br>
* 创建人：dengqiang<br>
* 创建时间：2017-11-15 14:49:56<br>
* 修改人：  <br>
* 修改时间：<br>
* 修改备注：<br>
* @version   V1.0
*/

@Service
@Transactional
public class PageContentInfoServiceImpl extends BaseServiceImpl<PageContentInfoModel,Integer> implements PageContentInfoService{
	Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private TypeInfoService typeInfoService;
	@Autowired
	private PageContentInfoMapper pageMapper;
	
	@Autowired
	public void setMapper(PageContentInfoMapper genericMapper) {
		super.setGenericMapper(genericMapper);
	}

	public GridDataModel getGridDataModelByCondition(Page po){
		Integer type = (Integer) po.getCondition().get("type");
		List<Integer> types = new ArrayList<Integer>();
		if(type != null){
			types.add(type);
			TypeInfoModel typeInfo = typeInfoService.getTypeById(type);
			types.addAll(typeInfo.getChildrenIds());
			po.addCondition("types", types);
			po.getCondition().remove("type");
		}
		Integer totalCount = countByCondition(po.getCondition());
		RowBounds rowBounds = new RowBounds(po.getOffset(), po.getPageSize());
		List<PageContentInfoModel> results = pageMapper.findListByCondition(po.getCondition(), rowBounds);
		return new GridDataModel(results, totalCount.intValue());
	}
}
